package com.lagou.edu.listener;

import com.lagou.edu.service.OrderService;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.io.UnsupportedEncodingException;

/**
 * @author stevejson
 */
@Component
public class OrderListener {

    @Autowired
    private OrderService orderService;

    @RabbitListener(queues = "queue.order.die", ackMode = "AUTO")
    public void handleOrderTtl(Message message) throws UnsupportedEncodingException {
        String id = new String(message.getBody(), message.getMessageProperties().getContentEncoding());
        System.out.println("死信队列"+id);
        Boolean success = orderService.cancelOrder(Integer.valueOf(id));
        System.out.println("死信队列"+id+success);
    }


}
